Page({

  data: {
    bank_num: '',
    name: '',
    id_number: '',
    phone: '',
    code: '',
    bankid: '',
    order: '',
    code_txt: '发送验证码',
    t: 60,
    time: 60,
    bank_list: [],
    value: -1,
  },

  onLoad(options) {
    this.getbanklist()
  },

  getbanklist() {
    getApp().globalData.post({
      url: '/api/applet.pay/getbanklist.html'
    }, true).then(res => {
      let bank_list = res.data.data
      bank_list.forEach((v, i) => {
        v.bank_txt = v.bank + '单笔限额:' + v.chux + ' | 今日限额:' + v.chuxday
      })
      this.setData({
        bank_list
      })
    })
  },

  change_val(e) {
    let val = e.currentTarget.dataset.val
    this.setData({
      [val]: e.detail.value
    })
  },

  change_bank(e) {
    this.setData({
      value: e.detail.value,
      bankid: this.data.bank_list[e.detail.value].id
    })
  },

  get_code() {
    if (this.data.time == this.data.t) {
      getApp().globalData.post({
        url: '/api/applet.pay/signSms.html',
        data: {
          bank_num: this.data.bank_num,
          bankid: this.data.bankid,
          name: this.data.name,
          id_number: this.data.id_number,
          phone: this.data.phone,
        }
      }, true).then(res => {
        if (res.data.code != 1) {
          getApp().showModal(res.data.msg)
        } else {
          this.setData({
            order: res.data.data.order
          })
          let time1 = setInterval(() => {
            if (this.data.time == 0) {
              this.setData({
                code_txt: '发送验证码',
                time: this.data.t
              })
              clearInterval(time1);
            } else {
              this.setData({
                code_txt: this.data.time + "秒后可重新获取",
                time: this.data.time - 1
              })
            }
          }, 1000)
        }
      })

    }
  },

  add() {
    if(!this.data.order){
      getApp().showModal('请先发送验证码')
      return
    }
    getApp().globalData.post({
      url: '/api/applet.pay/smsSign.html',
      data: {
        order: this.data.order,
        code: this.data.code,
      }
    }, true).then(res => {
      getApp().showModal(res.data.msg).then(() => {
        if (res.data.code == 1) {
          wx.navigateBack()
        }
      })
    })
  },

})